const TOKEN_NAME = 'hm-news-token'
const CHANNEL_NAME = 'hm-news-channel'
const HISTORY_NAME = 'hm-news-history'

// 提供存储历史记录的方法
export function setStorageHistory(value) {
  localStorage.setItem(HISTORY_NAME, JSON.stringify(value))
}

//
export const getStorageHistory = () => {
  return JSON.parse(localStorage.getItem(HISTORY_NAME)) || []
}

// 提供存储频道数据的方法
export function setStorageChannel(value) {
  localStorage.setItem(CHANNEL_NAME, JSON.stringify(value))
}

export function getStorageChannel(value) {
  // 获取数据,如果获取不到不需要设置默认值,会发送请求获取
  return JSON.parse(localStorage.getItem(CHANNEL_NAME))
}

export const setStorageToken = token => {
  localStorage.setItem(TOKEN_NAME, JSON.stringify(token))
}

export const removeStorageToken = () => {
  localStorage.removeItem(TOKEN_NAME)
}

export const getStorageToken = () => {
  return JSON.parse(localStorage.getItem(TOKEN_NAME)) || {}
}
